home *** CD-ROM | disk | FTP | other *** search
- /*
- File: FWSBP2DiskDriver.h
-
- Contains: Include file for sample SBP-2 disk driver
-
- Version: 1.0
-
- Copyright: © 1998-1999 by Apple Computer, Inc., all rights reserved.
-
- File Ownership:
-
- DRI: Clinton Bauder
-
- Other Contact: Eric Anderson
-
- Technology: FireWire
-
- Writers:
-
- (EA) Eric Anderson (ewa)
- (DCB) Clinton Bauder
-
- Change History (most recent first):
-
- <FW22> 4/30/99 EA Added fields to protect the LUN reset object from being used
- when it is already in use.
- <FW21> 4/29/99 DCB Cleaned up a few variables to simplify and improve our reset and
- reconnect handling.
- <FW20> 4/29/99 EA Add variables for restoring BUSY_TIMEOUT after a new login.
- <FW19> 3/31/99 EA Changed packet size from 256 to 1024.
- <FW18> 3/27/99 EA Add fields/enum for small-transfer double-buffer.
- <FW17> 3/8/99 DCB Get rid of unused variables, cleanup our login state variables
- and add some constants for payload size and error recovery
- control.
- <FW16> 3/4/99 DCB Support for write verification.
- <FW15> 3/2/99 DCB Put drive info in DrvSts2. Less of a hack this way, kinda sorta
- (the whole structure is a hack but at least its not MY hack.)
- <FW14> 2/22/99 EA Removed registrationRef; nobody was using it.
- <FW13> 2/16/99 DCB Add better support for 2 macs-1 drive, that is do the right
- thing if we fail a login.
- <FW12> 2/15/99 DCB Cleanup for Eric's notification changes.
- <FW11> 1/25/99 DCB Even yet more re-plug stuff.
- <FW10> 1/21/99 DCB Even more stuff for hot-plugging.
- <FW9> 1/19/99 DCB More stuff for unplugging/repluggin.
- <FW8> 1/15/99 DCB Stuff for unplugging drives.
- <FW7> 12/29/98 DCB Added a buffer for double buffering. Could get quite large if
- kMaxTransfer size is large enough.
- <FW6> 12/23/98 DCB Don't do ReqSense anymore as some drives don't like this. Back
- to straight retries for error checking. Also fixed up the
- Symbios ROM flash code.
- <FW5> 12/18/98 DCB Change use of login var.
- <FW4> 12/18/98 DCB Fixed Comment header. Time to go home...
- <FW3> 12/18/98 DCB A few changes for clear box support.
- <FW2> 11/17/98 DCB Misc Cleanup.
- <FW1> 11/17/98 DCB first checked in
- <FW2> 9/20/98 EA Filled in header comments.
- <FW1> 9/20/98 EA first checked in
- */
-
-
- #ifndef __FWSBP2DRIVER__
- #define __FWSBP2DRIVER__
-
- #ifndef __TYPES__
- #include <Types.h>
- #endif
- #ifndef __FIREWIRE__
- #include <FireWire.h>
- #endif
-
- #ifdef __cplusplus
- extern "C" {
- #endif
-
- #if PRAGMA_IMPORT_SUPPORTED
- #pragma import on
- #endif
-
- #if PRAGMA_ALIGN_SUPPORTED
- #pragma options align=mac68k
- #endif
-
- // Turn this on to read back all writes to compare the data. Uses about 125K of RAM for a max transfer of 250 blocks
- #define VerifyWrites 0
-
- // Turn this on if your device doesn't handle fetch agent resets properly
- #define needLUNReset 1
-
- enum {
-
- kBlockSize = 512,
- kMaxTransfer = 250, // Set to 1 for clear box drive
-
- kDiskDriverPayloadSize = 1024, // Packet size. 1024 is safe with FireWire 2.1 and setting the retry flag
-
- kSmallDoubleBufferSize = 8192, // Any request of this size or smaller will be double buffered.
- // This value is just a guess. It helps for single-block IO.
-
- kAsyncORB = 0,
- kImmedORB = 2,
- kTotalORBs = 3
-
- };
-
- struct FWSBP2DriverDataStruct
- {
- // Important! Next two items need to be at the front of this structure in order to be aligned properly!
-
- UInt8 dataBuffer[kMaxTransfer << 9]; // For double buffering. !!! Could get real big!
-
- #if VerifyWrites
- UInt8 verifyBuffer[kMaxTransfer << 9]; // For double buffering. !!! Could get real big!
- UInt8 * whatWasWritten;
- #endif
-
- FWDriverID fwDriverID; // Our driver ID.
- CSRROMEntryID csrUnitID; // Out unit directory ID.
- RegEntryID pRegEntryID;
-
- SInt16 drvrRefNum;
- Boolean gotEject; // True if we got ejected/offlined at some point...
- Boolean returnDiskErr; // True if user canceled the replug dialog
-
- FWCommandObjectID loginCommandID; // Login command object
-
- Boolean loggedIn; // True if we are logged in
- Boolean wasLoggedIn; // true if at some point we successfully logged into the drive.
- Boolean doubleBuffer; // True if we are double buffering this transfer.
- Boolean wait4Replug; // True if we're waiting for a re-plug.
- // Don't bother with reset notification or other nonsense
- // until FSL thinks we're back.
-
- volatile UInt32 loginObjBusy; // non - zero if login object is in use
-
- Boolean reLogin; // True if after a logout we want to try and login again
- Boolean reconnecting; // True if we are trying to reconnect.
- Boolean unused[2]; // Pad to longword
-
- SInt32 loginReqs; // Number of times an event occured triggering a login request
-
- FWAddress fetchAgent; // From login response.
-
- FWCommandObjectID orbID[4]; // ORB command objects 2 for Async, 1 for Immediate, 1 for other stuff
- UInt32 currentORB; // 1 or 0 depending on which one we're using
- FWCommandObjectID fwAGENT_RESET_ID; // Command object for FWWrite
- FWCommandObjectID fwLUNReset_ID; // Command object for resetting LUN with kSBP2LogicalUnitReset
- FWCommandObjectID fwReconnectID; // Command object for reconnecting after device goes away
- FWCommandObjectID fwReplugID; // Command object for requesting a drive re-plug
-
- volatile OSStatus immedStatus; // Status of immediate command
- volatile OSStatus utilStatus; // Status of utility command
-
- UInt32 xferLeft; // Used for really BIG transfers that can't
- // be completed with 1 10 byte command
- UInt32 next_block; // next block to xfer to
- Ptr next_buffer; // next chunk of buffer
-
- Boolean ioPending; // Used for error handling
- Boolean isWrite; // Used for retries and big commands
- Boolean queuedDQEl; // True if we called AddDrive.
- Boolean needsVerify;
- UInt32 retriesLeft; // ""
- UInt32 count; // ""
- UInt32 sector; // ""
- Ptr buffer; // ""
-
- FWAddress buffers[1]; // ""
- UInt32 lengths[1]; // ""
- UInt8 command[12]; // ""
- UInt8 aBuffer[12]; // Used for ReqSense
-
- IOParamPtr ioPB; // Remember the current parameter block and dce for
- DCtlEntry * dce; // the benefit of the async callback routine
- IOCommandID ioCommandID; // Remember command ID as well
-
- UInt32 totalBlocks; // Size of the disk in blocks
-
- Ptr smallBuffer; // Buffer for double-buffering small requests
- FWCommandObjectID smallBufferORB; // ORB reserved for small requests (static prepmemio)
- Boolean useSmallBuffer; // Small buffer is in use
- Boolean immediate; // Synchronous call, don't copy twice (zzz clean up)
- Boolean lunResetBusy; // fwLUNReset_ID is in use
- Boolean lunResetAgain; // ... and when done, we need to do it again
-
- FWCommandObjectID busyTimeoutCommandID; // Command object to set the BUSY_TIMEOUT register
- UInt32 busyTimeout; // Value to set each time
- Boolean busyTimeoutCommandBusy; // Flag set if command object in use
- Boolean busyTimeoutAgain; // Flag set if we should do it again
- Boolean unused3[2]; // Padding
-
- UInt32 bitBucket; // place to throw away data.
-
- // DrvSts2 is a particularly gross legacy structure. Using it is probably cleaner than trying
- // to duplicate the structure inside of our own globals although it introduces other inconveniences
- // when trying to use some of the fields within.
- DrvSts2 driveStatus;
-
- };
- typedef struct FWSBP2DriverDataStruct
- FWSBP2DriverData,
- *FWSBP2DriverDataPtr;
-
- struct sbpStatusBlockStruct
- {
- UInt8 stSrcRespLen;
- UInt8 stSBPStatus;
- UInt16 stOrbOffsetHi;
- UInt32 stOrbOffsetLo;
- UInt8 stStatus;
- UInt8 stKey;
- UInt8 stCode;
- UInt8 stQualifier;
- };
- typedef struct sbpStatusBlockStruct
- sbpStatusBlock,
- *sbpStatusBlockPtr;
-
-
- #if PRAGMA_ALIGN_SUPPORTED
- #pragma options align=reset
- #endif
-
- #if PRAGMA_IMPORT_SUPPORTED
- #pragma import off
- #endif
-
- #ifdef __cplusplus
- }
- #endif
-
- #endif /* __FWSBP2DRIVER__ */
-